package com.itm.lqm.servlets.course;

import java.io.IOException;




import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import com.itm.lqm.entity.Course;
import com.itm.lqm.service.CourseService;

/**
 * Servlet implementation class ManagerAddBook
 */
@WebServlet("/addCourse")
public class addCourse extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public addCourse() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
	}

	

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//获取添加页面的请求参数，然后调用业务逻辑层对象，实现最终修改
				request.setCharacterEncoding("UTF-8");
				response.setCharacterEncoding("UTF-8");
				response.setContentType("text/html; charset=UTF-8");
				

				
				int  cid= Integer.parseInt(request.getParameter("cid"));
				String cno =request.getParameter("cno");
				String cname =request.getParameter("cname");
				int tid =Integer.parseInt(request.getParameter("tid"));
				String taddress = request.getParameter("taddress");
				int sid = Integer.parseInt(request.getParameter("sid"));
				
				Course c= new Course(cid, cno, cname,sid,tid, taddress);
				CourseService cs=new CourseService();
				
				boolean result=cs.addCourse(c);
				
				System.out.println(result);
				if(result){
					//request.getRequestDispatcher("a.jsp").forward(request, response);
					request.getRequestDispatcher("findAllCourse").forward(request, response);
					
				}else{
					response.sendRedirect("addCourse.jsp");
				}
				
	}

}
